package com.task.core.domain.info;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import com.alibaba.fastjson2.JSON;
import com.task.common.info.ProxyInfo;

import lombok.Data;

/**
 * @author 迪迦.
 * @date 2025/1/16 11:23
 */
@Data
public class ClientProxyInfo {

  private Integer id;
  private String code;
  private String proxyName;
  private String proxyPlatformName;
  private Map<String, Object> config;


  public ClientProxyInfo() {
  }


  public ClientProxyInfo(ProxyInfo proxyInfo) {
    this.id = proxyInfo.getId();
    this.code = proxyInfo.getCode();
    this.proxyName = proxyInfo.getProxyName();
    this.proxyPlatformName = proxyInfo.getProxyPlatformName();
    if (!StringUtils.isEmpty(proxyInfo.getConfig())) {
      this.config = JSON.parseObject(proxyInfo.getConfig());
    }
  }


  public static List<ClientProxyInfo> getList(List<ProxyInfo> proxies) {
    if (CollectionUtils.isEmpty(proxies)) {
      return null;
    }
    List<ClientProxyInfo> list = new ArrayList<>();
    proxies.forEach(f -> {
      list.add(new ClientProxyInfo(f));
    });
    return list;
  }
}
